package voting

import (
	"fmt"
	"net/url"

	"awfan.cn/utils"
	"gopkg.in/mgo.v2"
)

func Get(u *url.URL, w http.ResponseWriter, body []byte,db *mgo.Database)() {
	switch u.Query().Get("t") {
	case "", "a":
		all(filepath.Ext(u.Path), w, db)
	}

	return nil, &utils.RESP_ERROR{404, fmt.Errorf("#'%v' query not supported")}
}

func Post(u *url.URL, w http.ResponseWriter, body []byte,db *mgo.Database)() {
	create(filepath.Ext(u.Path), decoder, w, db)
}

func Put(u *url.URL, w http.ResponseWriter, body []byte,db *mgo.Database)() {

	switch u.Query().Get("t") {
	case "", "i":
		edit(filepath.Ext(u.Path), u.Query().Get("id"), decoder, w, db)
	}
	return nil, &utils.RESP_ERROR{404, fmt.Errorf("#'%v' query not supported")}
}

func Del(u *url.URL, w http.ResponseWriter, body []byte,db *mgo.Database)() {
	switch u.Query().Get("t") {
	case "", "i":
		remove(filepath.Ext(u.Path), u.Query().Get("id"), w, db)
	}
	return nil, &utils.RESP_ERROR{404, fmt.Errorf("#'%v' query not supported")}

}
